package com.weiqiao.mall.repository.impl;

import com.mongodb.client.MongoCollection;
import com.weiqiao.base.dao.impl.BaseMongoDaoImpl;
import com.weiqiao.mall.repository.ISlideshowRepository;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 轮播图 持久化层 实现层
 *
 */
@Repository("SlideshowRepositoryImpl")
public class SlideshowRepositoryImpl extends BaseMongoDaoImpl implements ISlideshowRepository {
    private String collectionName = "wx_carouse";

    @Override
    public List<String> getCarouseList(Bson filter) {
        return this.findFilter(collectionName, filter);
    }


    @Override
    public boolean updateCarouse(Bson filter, String json) {
        return this.updateOne(collectionName, filter, json, true);
    }


    @Override
    public List<String> findCarouseList(int company_id, Document doc, Pageable pageable) {

        return this.getListAndPage(collectionName, doc, pageable);
    }


    @Override
    public int countByBson(Bson bson) {

        MongoCollection<Document> dbCollection = getCollection(collectionName);
        return (int) dbCollection.count(bson);
    }

    @Override
    public boolean deleteById(Bson filter) {
        return this.deleteOne(collectionName, filter);
    }

    @Override
    public List<String> getCarouseList(Document filter, Document project) {
        return super.findToProject(collectionName, filter, project);
    }


    @Override
    public List<String> getListByFilterSort(Bson filter, Bson sort) {

        List<String> result = this.findFilterSort(collectionName, filter, sort);
        return result;
    }

    @Override
    public String getOneByFilter(Bson filter) {

        String result = this.findOne(collectionName, filter);
        return result;
    }

    @Override
    public boolean updateCarouse(Bson filter, Document document) {
        return this.updateOne(collectionName, filter, document, false);
    }
}
